<script>
export default {
  name: "Person",
  props: {
    value: {
      type: Array,
      default: () => {
        return []
      },
      required: true
    },
    tips: {
      type: String,
      default: ''
    },
    mainId: {
      type: String,
      default: '',
      required: true
    },
    formData: {
      type: Object,
      default: () => {
        return {}
      },
      required: true
    },
    field: {
      type: String,
      default: '',
      required: true
    }
  },
  data() {
    return {}
  },
  methods: {
    addPerson() {
      this.value.push({'name': '','workUnit': '', 'mainId': this.mainId});
    },
    deletePerson(index) {
      this.value.splice(index, 1);
    }
  }
}
</script>

<template>
  <div>
    <el-button type="default" size="small" @click="addPerson">
      <el-icon class="el-icon-plus"></el-icon> &nbsp;新增主创人员
      <br>
      <br>
      <el-icon class="el-icon-plus"></el-icon>&nbsp;add more
    </el-button>
    <table class="tb-table" style="margin-top: 10px;">
      <tr class="tb-tr">
        <td class="tb-td tb-title" width="5%">#</td>
        <td class="tb-td tb-title" width="40%">姓名 Name</td>
        <td class="tb-td tb-title" width="40%">工作单位/就读院校 Workplace/Educational Institution</td>
        <td class="tb-td tb-title" width="15%">操作 Operation</td>
      </tr>
      <tr v-for="(item,index) in this.value" :key="index">
        <td class="tb-td">{{ index + 1 }}</td>
        <td class="tb-td">
          <el-input v-model="item.name" placeholder="请填写主创姓名" size="small" clearable style="width: 80%;"></el-input>
        </td>
        <td class="tb-td">
         <el-input v-model="item.workUnit" placeholder="请填写工作单位/就读院校/自由职业" size="small" clearable style="width: 80%;"></el-input>
        </td>
        <td class="tb-td">
          <el-button type="text" size="mini" icon="el-icon-delete" @click="deletePerson(index)">删除 Del</el-button>
        </td>
      </tr>
    </table>
  </div>
</template>

<style scoped>

.tb-table {
  text-align: center;
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

.tb-tr, .tb-td {
  border: 1px solid #ddd;
}
</style>
